package websocket.test.timer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import websocket.test.pojo.WebSocketMessage;
import websocket.test.servers.WebSocketServer;

import java.util.Date;

@Component
public class SendWsMessageInterval {
    @Autowired
    private WebSocketServer webSocketServer;
    @Scheduled(fixedRate = 10000)
    public void sendWsMessageInterval(){
       WebSocketMessage webSocketMessage=new WebSocketMessage();
       webSocketMessage.setState(200);
       webSocketMessage.setMessage("定时推送");
       webSocketMessage.setData(new Date().toLocaleString());
       webSocketServer.sendMsgToUser(1,webSocketMessage);
    }
}
